#ifndef MATH_H_
#define MATH_H_

#include "Vec.h"
#include "Vec2.h"
#include "Vec3.h"
#include "Vec4.h"
#include "Mat.h"
#include "Mat3.h"
#include "Mat4.h"
#include "geom_equations.h"

#include <cmath>

namespace physicsworks {

namespace math {
	
typedef Vec2<real> vec2;
typedef Vec3<real> vec3;
typedef Vec4<real> vec4;
typedef Mat3<real> mat3;
typedef Mat4<real> mat4;

/**
 * The Gram-Schmidt process (stabilized).
 * Returns 3 orthogonalized vectors. You must provide
 * 3 independent vectors.
 */
template<class T> inline void orthogonalize(Vec3<T>& v0, Vec3<T>& v1, Vec3<T>& v2)
{
	v0.normalize();
	
	v1 = v1 - (v0 * v1) * v0; // remove the component in direction v0
	v1.normalize();

	v2 = v2 - (v0 * v2) * v0; // remove the component in direction v0
	v2 = v2 - (v1 * v2) * v1; // remove the component in direction v1
	v2.normalize();
}

template<class T> inline Vec3<T> triangleCentroid(const Vec<T>& v0, const Vec<T>& v1, const Vec<T>& v2)
{
	return (v0 + v1 + v2) / 3;
}

}

}

#endif /*MATH_H_*/
